from spass.api.api_db import (del_user,
                              del_user_from_team,
                              del_team_from_teamset)
from spass.api.api_warehouse import (wdel_assignment_version,
                                     wdel_assignment_team,
                                     wdel_assignment,
                                     wdel_template)
from spass.core.error import error
import sys, os, datetime
from optparse import OptionParser

def callback_remove_user(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    del_user(parser.values.user[0], parser.values.user[1])

def callback_remove_user_from_team(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    del_user_from_team(int(parser.values.team[0]), parser.values.team[1], parser.values.team[2])

def callback_remove_team_from_teamset(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    del_team_from_teamset(parser.values.teamset[0], parser.values.teamset[1])

def callback_remove_assignment_version(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wdel_assignment_version(parser.values.version[0], parser.values.version[1], parser.values.version[2])

def callback_remove_assignment_w_team(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wdel_assignment_team(parser.values.team[0], parser.values.team[1])

def callback_remove_assignment_w(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wdel_assignment(parser.values.assignment)

def callback_remove_template_w(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wdel_template(parser.values.template)

def remove(argv):
    parser = OptionParser()
    parser.set_usage("""spass remove <options>""")
    parser.add_option("--user", action="callback", callback=callback_remove_user, type="string", nargs=2, dest="user", 
                      help="Removes an user from the database. ARG : <first name> <second name>")
    parser.add_option("--team", action="callback", callback=callback_remove_user_from_team, type="string", nargs=3, dest="team", 
                      help="Removes an user from a team. ARG : <first name> <second name>")
    parser.add_option("--teamset", action="callback", callback=callback_remove_team_from_teamset, type="int", nargs=2, dest="teamset", 
                      help="Removes a team from a teamset. ARG : <teamset ID> <team ID>")
    parser.add_option("--assignment-ver", action="callback", callback=callback_remove_assignment_version, type="string", nargs=3, dest="version",
                      help="Removes an assignment team version from the warehouse. ARG : <assignment ID> <team ID> <version ID>")
    parser.add_option("--assignment-w", action="callback", callback=callback_remove_assignment_w, type="string", nargs=1, dest="assignment",
                      help="Removes an assignment from the warehouse. ARG : <assignment ID>")
    parser.add_option("--assignment-w-team", action="callback", callback=callback_remove_assignment_w_team, type="string", nargs=2,
                      dest="Removes",help="Cleans an assignment team from the warehouse. ARG : <assignment ID> <team ID>")
    parser.add_option("--template-w", action="callback", callback=callback_remove_template_w, type="string", nargs=1, dest="template",
                      help="Removes a template from the warehouse. ARG : <template ID>")
    (options, args) = parser.parse_args(argv)
    return 0
